home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 31
/
Aminet 31 (1999)(Schatztruhe)[!][Jun 1999].iso
/
Aminet
/
dev
/
c
/
vbccppcsrc.lha
/
vbcc
/
vlink
/
vlink.h
< prev
Wrap
C/C++ Source or Header
|
1999-03-07
|
26KB
|
673 lines
/* $VER: vlink vlink.h V0.6d (13.02.99)
*
* This file is part of vlink, a portable linker for multiple
* object formats.
* Copyright (c) 1997-99 Frank Wille
*
* vlink is freeware and part of the portable and retargetable ANSI C
* compiler vbcc, copyright (c) 1995-99 by Volker Barthelmann.
* vlink may be freely redistributed as long as no modifications are
* made and nothing is charged for it. Non-commercial usage is allowed
* without any restrictions.
* EVERY PRODUCT OR PROGRAM DERIVED DIRECTLY FROM MY SOURCE MAY NOT BE
* SOLD COMMERCIALLY WITHOUT PERMISSION FROM THE AUTHOR.
*
*
* v0.6b (16.01.99) phx
* big_endian has to be "signed char" to compile under Irix 5.3.
* v0.6a (19.12.98) phx
* Endianess of linking process will be determined by the type
* of the first object.
* Support for little endian object file formats.
* New macros read16, write16, read32, write32 (replacing the old
* macros with the same name) for reading/writing data in the
* current endian format.
* v0.6 (24.10.98) phx
* baserel_off disappeared. Each target should know about its
* own small data section offset for the base register. The new
* field baseoff in FFFuncs was created for this purpose.
* New target elf32powerup, which supports the PPC coprocessor
* boards from Phase5.
* v0.5e (05.10.98) phx
* Artificial sections and objects, containing longwords sorted
* by priority, may be generated using new_priptr().
* Reduced hash table size for objects to 1/8 (32 entries).
* v0.5d (22.08.98) phx
* Faster memory allocation can be activated by #define FASTALLOC.
* Directories are only scanned if needed (AmigaOS filesystem is
* too slow).
* v0.5c (08.07.98) phx
* Automagic generation of @__xxx symbols for amigaehf.
* v0.5b (05.07.98) phx
* Linker symbols for elf32ppcbe.
* SYMX_SPECIAL in Symbol->extra flags a linker symbol as
* being target-specific
* v0.5 (27.06.98) phx
* Target-specific linker symbol support.
* v0.4 (05.06.98) phx
* New global vars for options: -sc, -sd, -multibase.
* New target-specific function targetlink(), which decides whether
* two sections must or must not be linked together for a target.
* find/create_lnksect() from linker.c are no longer global.
* linker_relrefs() finds all relative references between sections.
* The sections contain a RelRef-list afterwards, which can be
* used to link sections with relative references automatically
* together.
* v0.3b (25.04.98) phx
* t_elf.c was split into t_elf32.c and t_elf64.c
* New header files: elf64.h and rel_elfalpha.h
* Some experimental code for target elf64alpha in t_elf64.c
* v0.3a (18.04.98) phx
* Updated help text.
* v0.3 (17.04.98) phx
* ELF PowerPC 32Bit Big Endian support. Input: objects and
* library archives. Output: relocatabable objects.
* Full support for little endian file formats by defining new
* macros: LECH,LECW,LECVH,LECVW,read16le,read32le,write16le,
* write32le (although currently no LE formats are supported).
* Replaced l2bh(),l2bw(),read16(),read32(),write16(),write32()
* by swap16(),swap32(),read16sw(),read32sw(),write16sw(),write32sw().
* fwrite32() is now called fwrite32be().
* Section.id may contain a unique identification value.
* Included objname in struct LinkFile (useful for ELF archives).
* New option -F for reading a list of input files.
* Support for ar library archives.
* v0.2 (07.03.98) phx
* Linking of EHF and ADOS seems quite stable. Library units
* are linked immediately and are no longer always the last
* units in an output file.
* insertnode().
* v0.1 (27.02.98) phx
* First version that seems to link AmigaOS ADOS and EHF
* objects and libraries. Many common features, like linking
* sections together which have relative references, are
* still missing. Also, PowerPC-ELF32 support is about to come.
* v0.0 (04.08.97) phx
* File created. Project started on a beautiful summer-day
* at the North Sea beach of Cuxhaven. :)
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include <ctype.h>
#ifdef HAVE_CONFIG
#include "config.h"
#endif
/* program's name */
#define PNAME "vlink"
/* version/revision */
#define VERSION 0
#define REVISION 6
#define PLEVEL 4
/* integer types */
#if defined (TYPES32BIT)
typedef signed char int8;
typedef unsigned char uint8;
typedef signed short int int16;
typedef unsigned short int uint16;
typedef signed long int int32;
typedef unsigned long int uint32;
typedef signed char bool;
#elif defined (TYPES64BIT)
typedef signed char int8;
typedef unsigned char uint8;
typedef signed short int16;
typedef unsigned short uint16;
typedef signed int int32;
typedef unsigned int uint32;
typedef int bool;
#else
#error Unsupported architecture! Define either TYPES32BIT or TYPES64BIT.
#endif
/* endian conversion */
#if defined (BIGENDIAN)
#define ECH(x) x
#define ECW(x) x
#define ECVH(x) x
#define ECVW(x) x
#define read16be(x) (*(uint16 *)(x))
#define read32be(x) (*(uint32 *)(x))
#define write16be(x,y) (*(uint16 *)(x)=(y))
#define write32be(x,y) (*(uint32 *)(x)=(y))
#define LECH(x) (((x)&0xff)<<8|((x)&0xff00)>>8)
#define LECW(x) (((x)&0xff)<<24|((x)&0xff00)<<8|((x)&0xff0000)>>8|((x)&0xff000000)>>24)
#define LECVH(x) swap16(x)
#define LECVW(x) swap32(x)
#define read16le(x) read16sw(x)
#define read32le(x) read32sw(x)
#define write16le(x,y) write16sw(x,y)
#define write32le(x,y) write32sw(x,y)
#elif defined (LITTLEENDIAN)
#define ECH(x) (((x)&0xff)<<8|((x)&0xff00)>>8)
#define ECW(x) (((x)&0xff)<<24|((x)&0xff00)<<8|((x)&0xff0000)>>8|((x)&0xff000000)>>24)
#define ECVH(x) swap16(x)
#define ECVW(x) swap32(x)
#define read16be(x) read16sw(x)
#define read32be(x) read32sw(x)
#define write16be(x,y) write16sw(x,y)
#define write32be(x,y) write32sw(x,y)
#define LECH(x) x
#define LECW(x) x
#define LECVH(x) x
#define LECVW(x) x
#define read16le(x) (*(uint16 *)(x))
#define read32le(x) (*(uint32 *)(x))
#define write16le(x,y) (*(uint16 *)(x)=(y))
#define write32le(x,y) (*(uint32 *)(x)=(y))
#else
#error You have to define either BIGENDIAN or LITTLEENDIAN.
#endif
/* read/write data in current endianess */
#define read16(e,x) ((e)?(read16be(x)):(read16le(x)))
#define read32(e,x) ((e)?(read32be(x)):(read32le(x)))
#define write16(e,x,y) if(e) write16be(x,y); else write16le(x,y)
#define write32(e,x,y) if(e) write32be(x,y); else write32le(x,y)
/* program constants */
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef NULL
#define NULL 0
#endif
#define FNAMEBUFSIZE 1024 /* buffer size for file names */
#define MAX_FWALIGN 8192 /* max. aligment, when writing target file */
/* structures */
struct node {
struct node *next;
struct node *pred;
};
struct list {
struct node *first;
struct node *dummy;
struct node *last;
};
struct LibPath { /* libpaths list. */
struct node n; /* Here we search for library archives */
char *path; /* and shared objects. */
};
struct InputFile { /* inputlist nodes */
struct node n; /* contains names & flags of all inp. files */
char *name;
bool lib; /* search library */
bool dynamic; /* try to link dynamic first */
int so_ver; /* minimum version of shared object */
};
struct LinkFile {
struct node n;
char *pathname; /* full path: /usr/lib/libm.a */
char *filename; /* file name: libm.a */
char *objname; /* current obj. name: sin.o (archives only)*/
uint8 *data; /* pointer to file data */
unsigned long length; /* length of file */
uint8 format; /* file format - index into targets table */
uint8 type; /* ID_OBJECT/SHAREDOBJ/LIBARCH */
};
struct ObjectUnit {
struct node n;